package com.syh.jn.scm.service.impl.operation.system;

import com.alibaba.dubbo.config.annotation.Service;
import com.syh.core.ddd.infrastructure.repository.AggregateRepository;
import com.syh.core.ddd.service.AbstractServiceImpl;
import com.syh.jn.scm.domain.operation.entity.system.Dict;
import com.syh.jn.scm.domain.operation.repository.system.DictRepository;
import com.syh.jn.scm.dto.operation.system.dict.DictMto;
import com.syh.jn.scm.dto.operation.system.dict.DictSto;
import com.syh.jn.scm.dto.operation.system.dict.DictVo;
import com.syh.jn.scm.service.api.operation.system.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * Date:2018/7/13
 * Author:Clown
 * Desc;
 */
@Service
@Transactional
public class DictServiceImpl extends AbstractServiceImpl<DictSto, DictMto, DictVo,Dict,Long> implements DictService{
  @Autowired
  private DictRepository dictRepository;
  @Override
  protected AggregateRepository<Dict, Long> getAggregateRepository() { return dictRepository; }

  /**
   * 保存对象
   *
   * @param sto
   * @return
   */
  @Override
  public Long save(DictSto sto){
    Dict dict = new Dict(sto);
    dictRepository.add(dict);
    return dict.getId();
  }

  /**
   * 修改对象
   *
   * @param mto
   * @return
   */
  @Override
  public void update(DictMto mto){
    Dict dict = dictRepository.getById(mto.getId());
    dict.modify(mto);
    dictRepository.update(dict);
  }

  /**
   * 根据id删除对象
   *
   * @param id
   */
  @Override
  public void delete(Long id) {
    Dict dict = dictRepository.getById(id);
    dict.destroy();
    dictRepository.remove(dict);
  }

  /**
   * 启用分类
   *
   * @param id
   */
  @Override
  public void enabled(Long id){
   Dict dict = dictRepository.getById(id);
   dict.enabled();
   dictRepository.update(dict);
  }

  /**
   * 停用分类
   *
   * @param id
   */
  @Override
  public void disabled(Long id) {
    Dict dict = dictRepository.getById(id);
    dict.disabled();
    dictRepository.update(dict);
  }
}
